package ifmo.group5512.timer;

/**
 * Created with IntelliJ IDEA.
 * User: katerina
 * Date: 31.10.12
 * Time: 23:36
 * To change this template use File | Settings | File Templates.
 */
public class SynchronizationManager {

    public static InteractionProcessor initInteractionProcessor() {
        InteractionProcessor result = new InteractionProcessor();

        final int maxCounter = 10;
        int idx = 0;
        while (!(result.init()) && idx < maxCounter) {
            ++idx;
        }

        return result;
    }

    public static void main(String[] args) {

        InteractionProcessor interactionProcessor = initInteractionProcessor();
        if (!interactionProcessor.isInitialized()) {
            System.out.println("Fatal error. Unable to init InteractionProcessor after 10 repeated action.");
            System.out.println("SynchronizationManager will be closed.");
            System.exit(-1);
        }

        Thread systemInteraction = new Thread(interactionProcessor);
        systemInteraction.setDaemon(true);
        systemInteraction.start();

        Thread userInteraction = new Thread(new UserInputProcessor());
        userInteraction.start();
    }
}
